import Vue from 'vue'
import Router from 'vue-router'

//懒加载组件
const Home = () =>
    import ('../pages/home.vue')
const Index = () =>
    import ('../pages/index.vue')
const Product = () =>
    import ('../pages/product.vue')
const Detail = () =>
    import ('../pages/detail.vue')
const Cart = () =>
    import ('../pages/cart.vue')
const Order = () =>
    import ('../pages/order.vue')
    //子路由
const OrderConfirm = () =>
    import ('../pages/orderConfirm.vue')
const OrderList = () =>
    import ('../pages/orderList.vue')
const OrderPay = () =>
    import ('../pages/orderPay.vue')
const AliPay = () =>
    import ('../pages/alipay.vue')

//注册路由
Vue.use(Router)

//路由路径
const routes = [{
        path: '/',
        name: 'home',
        component: Home,
        redirect: '/index',
        children: [{
                path: '/index',
                name: 'index',
                component: Index
            },
            {
                path: '/product/:id',
                name: 'product',
                component: Product
            },
            {
                path: '/detail/:id',
                name: 'detail',
                component: Detail
            }
        ]
    },
    {
        path: '/cart',
        name: 'cart',
        component: Cart
    },
    {
        path: '/order',
        name: 'order',
        component: Order,
        children: [{
                path: 'list',
                name: 'order-list',
                component: OrderList
            },
            {
                path: 'confirm',
                name: 'order-confirm',
                component: OrderConfirm
            },
            {
                path: 'pay',
                name: 'order-pay',
                component: OrderPay
            },
            {
                path: 'alipay',
                name: 'alipay',
                component: AliPay
            }
        ]
    }
]

//导出路由
export default new Router({
    routes,
    mode: 'history'
})